/**************************************************************************
Step 1. Include necessary header files such that the stuff your test logic needs is declared. 
Don't forget gtest.h, which declares the testing framework.                                                   
**************************************************************************/
#include "gtest/gtest.h"
#include "include/pf_str.h"
#include "include/pf_errno.h"
#include "include/pf_internal.h"


/**************************************************************************
Step 2. Use test fixture to design your complex cases. 
You can add SetUp() to initialize the test data and 
TearDown() to clear the test data for common usage
Pls remember that when you using test fixture, need to use macro "TEST_F" instead of "TEST"                                                 
**************************************************************************/
class PfStrTest : public testing::Test 
{
    /* This SetUp() will be called before every TEST CASE which is marked by macro "TEST_F" */
    virtual void SetUp() 
    {

    }

    /* This TearDown will be called after every TEST CASE which is marked by macro "TEST_F" */
    virtual void TearDown() 
    {

    }

};

/***************************************************************************
Step 3. Use macro "TEST_F" to start your test case                                      
You can design your test case as the example
***************************************************************************/
TEST_F(PfStrTest, pfStr2HexTest)
{
    ::testing::FLAGS_gtest_death_test_style = "threadsafe"; /* avoid death warning */

    /* Define the local variables */
    int         ret                = -1;
    char* src_str_1                = "202122232425262728292A2B2C2D2E2F3a3b3c3d3e3f616263";
    char* src_str_2                = "dd5012e4b66bcf701e15dd18aca41295";  /* md5 digest */
    char* src_str_3                = "2E3D4F5H6G";  /* test case for char_2_int() == -1 in low 4-bits */
    char* src_str_4                = "3D4F5C#D";    /* test case for char_2_int() == -1 in high 4-bits */
    char* src_str_5                = "";            /* test case for zero str */
    char* src_str_6                = "9E83E";       /* test case for only high 4-bits */
    char* expected_hex_1           = " !\"#$%&\'()*+,-./:;<=>?abc";
    unsigned char expected_hex_2[] = {0xdd, 0x50, 0x12, 0xe4, 0xb6, 0x6b, 0xcf, 0x70,
                                      0x1e, 0x15, 0xdd, 0x18, 0xac, 0xa4, 0x12, 0x95};
    char hex_buff[256]   = {0};

    /* initilize test data for this case */
    /* Call your function for test */
    /* Check the result */
    /* Normal test */
    ret = pf_str_2_hex(hex_buff, sizeof(hex_buff), src_str_1);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_hex_1), strlen(hex_buff));
    EXPECT_EQ(0, memcmp(expected_hex_1, hex_buff, strlen(expected_hex_1)));

    ret = pf_str_2_hex(hex_buff, sizeof(hex_buff), src_str_2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(0, memcmp(expected_hex_2, hex_buff, sizeof(expected_hex_2)));

    ret = pf_str_2_hex(hex_buff, sizeof(hex_buff), src_str_3);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_hex(hex_buff, sizeof(hex_buff), src_str_4);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_hex(hex_buff, sizeof(hex_buff), src_str_5);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_hex(hex_buff, sizeof(hex_buff), src_str_6);
    EXPECT_EQ(PF_EINVAL, ret);

#ifndef VALGRIND_CHECK /* Death test core dump makes valgrind too many errors */
    /* Death Test */
    EXPECT_DEBUG_DEATH((ret = pf_str_2_hex(NULL, sizeof(hex_buff), src_str_1)), "");
    EXPECT_DEBUG_DEATH((ret = pf_str_2_hex(hex_buff, sizeof(hex_buff), NULL)), "");
#endif /* #ifndef VALGRIND_CHECK */

    ret = pf_str_2_hex(hex_buff, 0, src_str_1);
    EXPECT_EQ(PF_EINVAL, ret);
    /* Clear the test data for this case */
}

TEST_F(PfStrTest, pfHex2StrTest)
{
    ::testing::FLAGS_gtest_death_test_style = "threadsafe"; /* avoid death warning */

    /* Define the local variables */
    int ret                   = -1;
    char* src_hex_1           = "aBcDeFg1234%^&*";
    unsigned char src_hex_2[] = {0xdd, 0x50, 0x12, 0xe4, 0xb6, 0x6b, 0xcf, 0x70,
                                 0x1e, 0x15, 0xdd, 0x18, 0xac, 0xa4, 0x12, 0x95}; /* md5 digest */
    unsigned char src_hex_3[] = {0x00}; /* test case for zero */
    char* src_hex_4           = ""; /* test case for zero string */
    char* expected_str_1      = "6142634465466731323334255E262A";
    char* expected_str_2      = "dd5012e4b66bcf701e15dd18aca41295";
    char* expected_str_3      = "00";
    char hex_buff[256]        = {0};

    /* initilize test data for this case */
    /* Call your function for test */
    /* Check the result */
    ret = pf_hex_2_str(hex_buff, sizeof(hex_buff), src_hex_1, strlen(src_hex_1), 0);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_1), strlen(hex_buff));
    EXPECT_EQ(0, memcmp(expected_str_1, hex_buff, strlen(hex_buff)));

    ret = pf_hex_2_str(hex_buff, sizeof(hex_buff), src_hex_2, sizeof(src_hex_2), 1);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_2), strlen(hex_buff));
    EXPECT_EQ(0, memcmp(expected_str_2, hex_buff, strlen(hex_buff)));

    ret = pf_hex_2_str(hex_buff, sizeof(hex_buff), src_hex_3, sizeof(src_hex_3), 0);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_3), strlen(hex_buff));
    EXPECT_EQ(0, memcmp(expected_str_3, hex_buff, strlen(hex_buff)));

    ret = pf_hex_2_str(hex_buff, sizeof(hex_buff), src_hex_4, strlen(src_hex_4), 1);
    EXPECT_EQ(PF_EINVAL, ret);

#ifndef VALGRIND_CHECK /* Death test core dump makes valgrind too many errors */
    /* Death Test */
    EXPECT_DEBUG_DEATH((ret = pf_hex_2_str(NULL, sizeof(hex_buff), src_hex_1, strlen(src_hex_1), 1)), "");
    EXPECT_DEBUG_DEATH((ret = pf_hex_2_str(hex_buff, sizeof(hex_buff), NULL, strlen(src_hex_1), 0)), "");
#endif /* #ifndef VALGRIND_CHECK */

    ret = pf_hex_2_str(hex_buff, 0, src_hex_1, strlen(src_hex_1), 1);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_hex_2_str(hex_buff, 1, src_hex_1, strlen(src_hex_1), 0);
    EXPECT_EQ(PF_EINVAL, ret);

    /* Clear the test data for this case */
}

TEST_F(PfStrTest, pfInt2StrTest)
{
    ::testing::FLAGS_gtest_death_test_style = "threadsafe"; /* avoid death warning */

    /* Define the local variables */
    int ret                = -1;
    int64_t input_1        = 189234934072323302LL;
    int64_t input_2        = INT64_MAX;
    int64_t input_3        = -98234234234LL;
    int64_t input_4        = INT64_MIN;
    int64_t input_5        = -52026871233030555LL;
    int64_t input_6        = 50925925536831LL;
    char* expected_str10_1 = "189234934072323302";
    char* expected_str8_1  = "12402302560036326346";
    char* expected_str10_2 = "9223372036854775807";
    char* expected_str16_2 = "7FFFFFFFFFFFFFFF";
    char* expected_str10_3 = "-98234234234";
    char* expected_str2_3  = "1111111111111111111111111110100100100000110010001000101010000110";
    char* expected_str10_4 = "-9223372036854775808";
    char* expected_str16_4 = "8000000000000000";
    char* expected_str36_5 = "-E89ZIOU4ZA3";
    char* expected_str9_6  = "220273638362030";
    char buff[256]         = {0};

    /* initilize test data for this case */
    /* Call your function for test */
    /* Check the result */
    ret = pf_int_2_str(buff, sizeof(buff), input_1, 0, 10);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str10_1), strlen(buff));
    EXPECT_STREQ(expected_str10_1, buff);

    ret = pf_int_2_str(buff, sizeof(buff), input_1, 0, 8);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str8_1), strlen(buff));
    EXPECT_STREQ(expected_str8_1, buff);

    ret = pf_int_2_str(buff, sizeof(buff), input_2, 1, 0);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str10_2), strlen(buff));
    EXPECT_STREQ(expected_str10_2, buff);

    ret = pf_int_2_str(buff, sizeof(buff), input_2, 0, 16);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str16_2), strlen(buff));
    EXPECT_STREQ(expected_str16_2, buff);

    ret = pf_int_2_str(buff, sizeof(buff), input_3, 1, 10);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str10_3), strlen(buff));
    EXPECT_STREQ(expected_str10_3, buff);

    ret = pf_int_2_str(buff, sizeof(buff), input_3, 1, 2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str2_3), strlen(buff));
    EXPECT_STREQ(expected_str2_3, buff);

    ret = pf_int_2_str(buff, sizeof(buff), input_4, 1, 0);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str10_4), strlen(buff));
    EXPECT_STREQ(expected_str10_4, buff);

    ret = pf_int_2_str(buff, sizeof(buff), input_4, 1, 16);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str16_4), strlen(buff));
    EXPECT_STREQ(expected_str16_4, buff);

    ret = pf_int_2_str(buff, sizeof(buff), input_5, 0, 36);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str36_5), strlen(buff));
    EXPECT_STREQ(expected_str36_5, buff);

    ret = pf_int_2_str(buff, sizeof(buff), input_6, 0, 9);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str9_6), strlen(buff));
    EXPECT_STREQ(expected_str9_6, buff);

#ifndef VALGRIND_CHECK /* Death test core dump makes valgrind too many errors */
    /* Death Test */
    EXPECT_DEBUG_DEATH((ret = pf_int_2_str(NULL, sizeof(buff), input_1, 0, 10)), "");
#endif /* #ifndef VALGRIND_CHECK */

    ret = pf_int_2_str(buff, -1, input_1, 0, 10);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_int_2_str(buff, sizeof(buff), input_1, 0, 60);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_int_2_str(buff, sizeof(buff), input_1, 0, 1);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_int_2_str(buff, sizeof(buff), input_1, 0, -10);
    EXPECT_EQ(PF_EINVAL, ret);

    /* Test case for buffer not enough for '\0' */
    ret = pf_int_2_str(buff, 18, input_1, 0, 10);
    EXPECT_EQ(PF_EINVAL, ret);

    /* Clear the test data for this case */

}

TEST_F(PfStrTest, pfStr2Int32Test)
{
    ::testing::FLAGS_gtest_death_test_style = "threadsafe"; /* avoid death warning */

    /* Define the local variables */
    int ret                   = -1;
    int32_t output            = -1;
    const char* str10_1       = "18923493";
    const char* str8_1        = "110137745";
    const char* str10_2       = "2147483647";
    const char* str16_2       = "7FFFFFFF";
    const char* str10_3       = "-9826357";
    //const char* str2_3        = "11111111011010100000111111001011";
    const char* str10_4       = "-2147483648";
    //const char* str16_4       = "80000000";
    const char* str36_5       = "-E89Z1";
    const char* str9_6        = "273635043";
    const char* str36_7       = "ZEEROEROWYERWYOUWEYZ19"; /* test case for overflow value */
    const char* str10_8       = "1380ABC";                /* test case for invalid value */
    const char* str10_9       = "";                       /* test case for zero string */
    int32_t expected_output_1 = 18923493;
    int32_t expected_output_2 = INT32_MAX;
    int32_t expected_output_3 = -9826357;
    int32_t expected_output_4 = INT32_MIN;
    int32_t expected_output_5 = -23900797;
    int32_t expected_output_6 = 121546209;

    /* initilize test data for this case */
    /* Call your function for test */
    /* Check the result */
    ret = pf_str_2_int32(&output, str10_1, 10);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_1, output);

    ret = pf_str_2_int32(&output, str8_1, 8);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_1, output);

    ret = pf_str_2_int32(&output, str10_2, 0);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_2, output);

    ret = pf_str_2_int32(&output, str16_2, 16);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_2, output);

    ret = pf_str_2_int32(&output, str10_3, 10);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_3, output);

    /* strtol() return ERANGE, underflow, unsupport 32-bits "0101" string.
     *
    ret = pf_str_2_int32(&output, str2_3, 2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_3, output);
    */

    ret = pf_str_2_int32(&output, str10_4, 0);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_4, output);

    /* strtol() return ERANGE, underflow, unsupport INT32_MIN HEX STRING.
     *
    ret = pf_str_2_int32(&output, str16_4, 16);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_4, output);
    */

    ret = pf_str_2_int32(&output, str36_5, 36);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_5, output);

    ret = pf_str_2_int32(&output, str9_6, 9);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_6, output);

#ifndef VALGRIND_CHECK /* Death test core dump makes valgrind too many errors */
    /* Death Test */
    EXPECT_DEBUG_DEATH((ret = pf_str_2_int32(NULL, str10_1, 10)), "");
    EXPECT_DEBUG_DEATH((ret = pf_str_2_int32(&output, NULL, 10)), "");
#endif /* ifndef VALGRIND_CHECK */

    ret = pf_str_2_int32(&output, str10_1, 60);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_int32(&output, str36_7, 36);
    EXPECT_EQ(PF_ERANGE, ret);

    ret = pf_str_2_int32(&output, str10_8, 10);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_int32(&output, str10_9, 10);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(0, output);

    /* Clear the test data for this case */
}

TEST_F(PfStrTest, pfStr2Int64Test)
{
    ::testing::FLAGS_gtest_death_test_style = "threadsafe"; /* avoid death warning */

    /* Define the local variables */
    int ret                   = -1;
    int64_t output            = -1;
    const char* str10_1       = "189234934072323302";
    const char* str8_1        = "12402302560036326346";
    const char* str10_2       = "9223372036854775807";
    const char* str16_2       = "7FFFFFFFFFFFFFFF";
    const char* str10_3       = "-98234234234";
    //const char* str2_3        = "1111111111111111111111111110100100100000110010001000101010000110";
    const char* str10_4       = "-9223372036854775808";
    //const char* str16_4       = "8000000000000000";
    const char* str36_5       = "-E89ZIOU4ZA3";
    const char* str9_6        = "220273638362030";
    const char* str36_7       = "ZEEROEROWYERWYOUWEYZ19"; /* test case for overflow value */
    const char* str10_8       = "1380ABC";                /* test case for invalid value */
    const char* str10_9       = "";                       /* test case for zero string */
    int64_t expected_output_1 = 189234934072323302LL;
    int64_t expected_output_2 = INT64_MAX;
    int64_t expected_output_3 = -98234234234LL;
    int64_t expected_output_4 = INT64_MIN;
    int64_t expected_output_5 = -52026871233030555LL;
    int64_t expected_output_6 = 50925925536831LL;

    /* initilize test data for this case */
    /* Call your function for test */
    /* Check the result */
    ret = pf_str_2_int64(&output, str10_1, 10);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_1, output);

    ret = pf_str_2_int64(&output, str8_1, 8);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_1, output);

    ret = pf_str_2_int64(&output, str10_2, 0);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_2, output);

    ret = pf_str_2_int64(&output, str16_2, 16);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_2, output);

    ret = pf_str_2_int64(&output, str10_3, 10);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_3, output);

    /* strtoll() return ERANGE, underflow, unsupport 64-bits "0101" string.
     *
    ret = pf_str_2_int64(&output, str2_3, 2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_3, output);
    */

    ret = pf_str_2_int64(&output, str10_4, 0);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_4, output);

    /* strtoll() return ERANGE, underflow, unsupport INT64_MIN HEX STRING.
     *
    ret = pf_str_2_int64(&output, str16_4, 16);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_4, output);
    */

    ret = pf_str_2_int64(&output, str36_5, 36);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_5, output);

    ret = pf_str_2_int64(&output, str9_6, 9);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_6, output);

#ifndef VALGRIND_CHECK /* Death test core dump makes valgrind too many errors */
    /* Death Test */
    EXPECT_DEBUG_DEATH((ret = pf_str_2_int64(NULL, str10_1, 10)), "");
    EXPECT_DEBUG_DEATH((ret = pf_str_2_int64(&output, NULL, 10)), "");
#endif /* #ifndef VALGRIND_CHECK */

    ret = pf_str_2_int64(&output, str10_1, 60);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_int64(&output, str36_7, 36);
    EXPECT_EQ(PF_ERANGE, ret);

    ret = pf_str_2_int64(&output, str10_8, 10);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_int64(&output, str10_9, 10);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(0, output);

    /* Clear the test data for this case */
}

TEST_F(PfStrTest, pfStrTrimTest)
{
    ::testing::FLAGS_gtest_death_test_style = "threadsafe"; /* avoid death warning */

    /* Define the local variables */
    char* ret                    = NULL;
    char src_str_1[]             = " wwer\r\nyouwx wer \r\n";
    char src_str_2[]             = " wwer\r\nyouwx wer \r\n";
    char src_str_3[]             = " wwer\r\nyouwx wer \r\n";
    char src_str_4[]             = " \t\t\b\r\n     \t\t\n\b";
    char src_str_5[]             = "";
    char src_str_6[]             = "rc d";
    const char* sp_str_1         = " \b\t\n\r";
    const char* sp_str_2         = " ";
    const char* sp_str_3         = "";
    const char* sp_str_4         = "dbaef(*)ab";
    const char* expected_str_1_1 = "wwer\r\nyouwx wer";
    const char* expected_str_2_2 = "wwer\r\nyouwx wer \r\n";
    const char* expected_str_3_3 = " wwer\r\nyouwx wer \r\n";
    const char* expected_str_4_1 = "";
    const char* expected_str_5_1 = "";
    const char* expected_str_6_4 = "rc ";

    /* initilize test data for this case */
    /* Call your function for test */
    /* Check the result */
    ret = pf_str_trim(src_str_1, sp_str_1);
    EXPECT_STREQ(expected_str_1_1, ret);

    ret = pf_str_trim(src_str_2, sp_str_2);
    EXPECT_STREQ(expected_str_2_2, ret);

    ret = pf_str_trim(src_str_3, sp_str_3);
    EXPECT_STREQ(expected_str_3_3, ret);

    ret = pf_str_trim(src_str_4, sp_str_1);
    EXPECT_STREQ(expected_str_4_1, ret);

    ret = pf_str_trim(src_str_5, sp_str_1);
    EXPECT_STREQ(expected_str_5_1, ret);

    ret = pf_str_trim(src_str_5, sp_str_1);
    EXPECT_STREQ(expected_str_5_1, ret);

    ret = pf_str_trim(src_str_6, sp_str_4);
    EXPECT_STREQ(expected_str_6_4, ret);

#ifndef VALGRIND_CHECK /* Death test core dump makes valgrind too many errors */
    /* Death Test */
    EXPECT_DEBUG_DEATH((ret = pf_str_trim(NULL, sp_str_1)), "");
    EXPECT_DEBUG_DEATH((ret = pf_str_trim(src_str_1, NULL)), "");
#endif /* #ifndef VALGRIND_CHECK */

    /* Clear the test data for this case */
}

TEST_F(PfStrTest, pfStr2IntWithUnit)
{
    ::testing::FLAGS_gtest_death_test_style = "threadsafe"; /* avoid death warning */

    /* Define the local variables */
    int32_t ret = -1;
    int64_t output = -1;
    const char* str_b_1 = "20";
    const char* str_b_2 = "-303B";
    const char* str_b_3 = "9.7b";
    const char* str_k_1 = "50K";
    const char* str_k_2 = "-30.77k";
    const char* str_m_1 = "-160M";
    const char* str_m_2 = "6060.40m";
    const char* str_g_1 = "800G";
    const char* str_g_2 = "30.9g";
    const char* str_t_1 = "1024T";
    const char* str_t_2 = "1024.8t";
    const char* str_p_1 = "3P";
    const char* str_p_2 = "398.15p";
    const char* str_e_1 = "1.385E";
    const char* str_e_2 = "7e";
    const char* str_err_1 = "1038BdC";
    const char* str_err_2 = "M103B";
    const char* str_err_3 = "G";
    const char* str_err_4 = "103Z";
    int64_t expected_output_b_1 = 20;
    int64_t expected_output_b_2 = -303LL;
    int64_t expected_output_b_3 = int64_t(9.7);
    int64_t expected_output_k_1 = 50 * 1024;
    int64_t expected_output_k_2 = int64_t(-30.77 * 1024LL);
    int64_t expected_output_m_1 = -160 * 1024LL * 1024LL;
    int64_t expected_output_m_2 = int64_t(6060.40 * 1024LL * 1024LL);
    int64_t expected_output_g_1 = 800LL * 1024LL * 1024LL * 1024LL;
    int64_t expected_output_g_2 = int64_t(30.9 * 1024LL * 1024LL * 1024LL);
    int64_t expected_output_t_1 = 1024LL * 1024LL * 1024LL * 1024LL * 1024LL;
    int64_t expected_output_t_2 = int64_t(1024.8 * 1024LL * 1024LL * 1024LL * 1024LL);
    int64_t expected_output_p_1 = 3LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL;
    int64_t expected_output_p_2 = int64_t(398.15 * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL);
    int64_t expected_output_e_1 = int64_t(1.385 * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL);
    int64_t expected_output_e_2 = 7LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL;

    /* initilize test data for this case */
    /* Call your function for test */
    /* Check the result */
    ret = pf_str_2_int_with_unit(&output, str_b_1);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_b_1, output);

    ret = pf_str_2_int_with_unit(&output, str_b_2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_b_2, output);

    ret = pf_str_2_int_with_unit(&output, str_b_3);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_b_3, output);

    ret = pf_str_2_int_with_unit(&output, str_k_1);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_k_1, output);

    ret = pf_str_2_int_with_unit(&output, str_k_2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_k_2, output);

    ret = pf_str_2_int_with_unit(&output, str_m_1);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_m_1, output);

    ret = pf_str_2_int_with_unit(&output, str_m_2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_m_2, output);

    ret = pf_str_2_int_with_unit(&output, str_g_1);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_g_1, output);

    ret = pf_str_2_int_with_unit(&output, str_g_2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_g_2, output);

    ret = pf_str_2_int_with_unit(&output, str_t_1);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_t_1, output);

    ret = pf_str_2_int_with_unit(&output, str_t_2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_t_2, output);

    ret = pf_str_2_int_with_unit(&output, str_p_1);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_p_1, output);

    ret = pf_str_2_int_with_unit(&output, str_p_2);
    EXPECT_EQ(0, ret);
    EXPECT_NEAR(expected_output_p_2, output, 50);

    ret = pf_str_2_int_with_unit(&output, str_e_1);
    EXPECT_EQ(0, ret);
    EXPECT_NEAR(expected_output_e_1, output, 50);

    ret = pf_str_2_int_with_unit(&output, str_e_2);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(expected_output_e_2, output);

    ret = pf_str_2_int_with_unit(&output, str_err_1);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_int_with_unit(&output, str_err_2);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_int_with_unit(&output, str_err_3);
    EXPECT_EQ(PF_EINVAL, ret);

    ret = pf_str_2_int_with_unit(&output, str_err_4);
    EXPECT_EQ(PF_EINVAL, ret);

#ifndef VALGRIND_CHECK /* Death test core dump makes valgrind too many errors */
    /* Death Test */
    EXPECT_DEBUG_DEATH((ret = pf_str_2_int_with_unit(NULL, str_b_1)), "");
    EXPECT_DEBUG_DEATH((ret = pf_str_2_int_with_unit(&output, NULL)), "");
#endif /* #ifndef VALGRIND_CHECK */

    /* Zero Test */
    ret = pf_str_2_int_with_unit(&output, "");
    EXPECT_EQ(PF_EINVAL, ret);

    /* Clear the test data for this case */
}

TEST_F(PfStrTest, pfInt2StrWithUnit)
{
    ::testing::FLAGS_gtest_death_test_style = "threadsafe"; /* avoid death warning */

    /* Define the local variables */
    int32_t ret = -1;
    int64_t input_b_1 = 20;
    int64_t input_b_2 = -303LL;
    int64_t input_b_3 = int64_t(9.7);
    int64_t input_k_1 = 50 * 1024;
    int64_t input_k_2 = int64_t(-30.77 * 1024LL);
    int64_t input_m_1 = -160 * 1024LL * 1024LL;
    int64_t input_m_2 = int64_t(6060.40 * 1024LL * 1024LL);
    int64_t input_g_1 = 800LL * 1024LL * 1024LL * 1024LL;
    int64_t input_g_2 = int64_t(30.9 * 1024LL * 1024LL * 1024LL);
    int64_t input_t_1 = 1024LL * 1024LL * 1024LL * 1024LL * 1024LL;
    int64_t input_t_2 = int64_t(1024.8 * 1024LL * 1024LL * 1024LL * 1024LL);
    int64_t input_p_1 = 3LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL;
    int64_t input_p_2 = int64_t(398.15 * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL);
    int64_t input_e_1 = int64_t(1.385 * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL);
    int64_t input_e_2 = 7LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL;
    const char* expected_str_b_1 = "20.00B";
    const char* expected_str_b_2 = "-303.00B";
    const char* expected_str_b_3 = "9.00b";
    const char* expected_str_k_1 = "50.00K";
    const char* expected_str_k_2 = "-30.77k";
    const char* expected_str_m_1 = "-160.00M";
    const char* expected_str_m_2 = "6060.40m";
    const char* expected_str_g_1 = "800.00G";
    const char* expected_str_g_2 = "30.90g";
    const char* expected_str_t_1 = "1024.00T";
    const char* expected_str_t_2 = "1024.80t";
    const char* expected_str_p_1 = "3.00P";
    const char* expected_str_p_2 = "398.15p";
    const char* expected_str_e_1 = "1.39E";
    const char* expected_str_e_2 = "7.00e";
    char buff[256] = {0};

    /* initilize test data for this case */
    /* Call your function for test */
    /* Check the result */
    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_b_1, 0);
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_b_1), strlen(buff));
    EXPECT_STREQ(expected_str_b_1, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_b_2, 'B');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_b_2), strlen(buff));
    EXPECT_STREQ(expected_str_b_2, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_b_3, 'b');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_b_3), strlen(buff));
    EXPECT_STREQ(expected_str_b_3, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_k_1, 'K');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_k_1), strlen(buff));
    EXPECT_STREQ(expected_str_k_1, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_k_2, 'k');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_k_2), strlen(buff));
    EXPECT_STREQ(expected_str_k_2, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_m_1, 'M');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_m_1), strlen(buff));
    EXPECT_STREQ(expected_str_m_1, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_m_2, 'm');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_m_2), strlen(buff));
    EXPECT_STREQ(expected_str_m_2, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_g_1, 'G');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_g_1), strlen(buff));
    EXPECT_STREQ(expected_str_g_1, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_g_2, 'g');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_g_2), strlen(buff));
    EXPECT_STREQ(expected_str_g_2, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_t_1, 'T');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_t_1), strlen(buff));
    EXPECT_STREQ(expected_str_t_1, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_t_2, 't');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_t_2), strlen(buff));
    EXPECT_STREQ(expected_str_t_2, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_p_1, 'P');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_p_1), strlen(buff));
    EXPECT_STREQ(expected_str_p_1, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_p_2, 'p');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_p_2), strlen(buff));
    EXPECT_STREQ(expected_str_p_2, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_e_1, 'E');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_e_1), strlen(buff));
    EXPECT_STREQ(expected_str_e_1, buff);

    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_e_2, 'e');
    EXPECT_EQ(0, ret);
    EXPECT_EQ(strlen(expected_str_e_2), strlen(buff));
    EXPECT_STREQ(expected_str_e_2, buff);


#ifndef VALGRIND_CHECK /* Death test core dump makes valgrind too many errors */
    /* Death Test */
    EXPECT_DEBUG_DEATH((ret = pf_int_2_str_with_unit(NULL, sizeof(buff), input_b_1, 'B')), "");
#endif /* #ifndef VALGRIND_CHECK */

    /* Zero Test */
    ret = pf_int_2_str_with_unit(buff, 0, input_b_1, 'B');
    EXPECT_EQ(PF_EINVAL, ret);

    /* Test case for buffer not enough */
    ret = pf_int_2_str_with_unit(buff, 1, input_b_1, 'B');
    EXPECT_EQ(PF_EINVAL, ret);

    /* Test case for invalid unit */
    ret = pf_int_2_str_with_unit(buff, sizeof(buff), input_b_1, 'X');
    EXPECT_EQ(PF_EINVAL, ret);

    /* Clear the test data for this case */
}
